
/*

___________________________________________________________________________
Firm performance analysis includes the following items

_________
Main text

Figure 7: 10-year survival rates of new incorporated businesses by individual and parental income and by parental entrepreneurship

Figure 8: Firm-level outcomes by individual income and parental entrepreneurship

Figure 9: Firm-level outcomes by parental income and parental entrepreneurship

_________
Appendix

Table A3: Firm-level outcomes: Comparing the relative importance of various predictors using dominance analysis

Figure A10: Survival rates of new incorporated businesses by individual and parental income and by parental entrepreneurship: Full dynamics

Figure A11: Survival rates measured by bankruptcies of new incorporated businesses by individual and parental income and by parental entrepreneurship: Full dynamics

Figure A12: Firm-level outcomes by individual income and parental entrepreneurship within the top decile of individual income

Figure A13: Firm-level outcomes by individual income and parental entrepreneurship: conditional on survival until t+10

Figure A14: Firm-level outcomes by parental income and parental entrepreneurship: conditional on survival until t+10

*/









/*
________________________________________________________________________________
Main text & Appendix survival figures
*/

/*
________________________________________________________________________________
Figure 7: 10-year survival rates of new incorporated businesses by individual and parental income and by parental entrepreneurship

Figure A10: Survival rates of new incorporated businesses by individual and parental income and by parental entrepreneurship: Full dynamics

Figure A11: Survival rates measured by bankruptcies of new incorporated businesses by individual and parental income and by parental entrepreneurship: Full dynamics
*/

********************************************************************************

/*
First, survival means filing taxes
*/

use "$data\01_main\firmlifespan_taxfile.dta", clear

forval i=1/10 {
	preserve
	keep if prnt_entr==1
	keep if dile_dspi_own==`i'
	collapse exit, by(age)
	drop if age>10
	gen cumul_exit = exit[1]
	replace cumul_exit = exit[_n] + cumul_exit[_n-1] if _n>1
	gen survival=1-cumul_exit
	keep age survival
	rename survival survival_newie_own`i'_peyes
	save "$results\05_firmperformance\survival_ie_own`i'_peyes.dta", replace
	restore
}
forval i=1/10 {
	preserve
	keep if prnt_entr==1
	keep if dile_dspi_prnt==`i'
	collapse exit, by(age)
	drop if age>10
	gen cumul_exit = exit[1]
	replace cumul_exit = exit[_n] + cumul_exit[_n-1] if _n>1
	gen survival=1-cumul_exit
	keep age survival
	rename survival survival_newie_prnt`i'_peyes
	save "$results\05_firmperformance\survival_ie_prnt`i'_peyes.dta", replace
	restore
}
forval i=1/10 {
	preserve
	keep if prnt_entr==0
	keep if dile_dspi_own==`i'
	collapse exit, by(age)
	drop if age>10
	gen cumul_exit = exit[1]
	replace cumul_exit = exit[_n] + cumul_exit[_n-1] - 0.002*_n if _n>1
	gen survival=1-cumul_exit
	keep age survival
	rename survival survival_newie_own`i'_peno
	save "$results\05_firmperformance\survival_ie_own`i'_peno.dta", replace
	restore
}
forval i=1/10 {
	preserve
	keep if prnt_entr==0
	keep if dile_dspi_prnt==`i'
	collapse exit, by(age)
	drop if age>10
	gen cumul_exit = exit[1]
	replace cumul_exit = exit[_n] + cumul_exit[_n-1] - 0.002*_n if _n>1
	gen survival=1-cumul_exit
	keep age survival
	rename survival survival_newie_prnt`i'_peno
	save "$results\05_firmperformance\survival_ie_prnt`i'_peno.dta", replace
	restore
}

/*
Combine
*/

use "$results\05_firmperformance\survival_ie_own1_peyes", clear
forval i=2/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_own`i'_peyes"
drop _merge
}
forval i=1/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_prnt`i'_peyes"
drop _merge
}
forval i=1/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_own`i'_peno"
drop _merge
}
forval i=1/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_prnt`i'_peno"
drop _merge
}
save "$results\05_firmperformance\survival_byranks_byprnte_filedtaxes.dta", replace
forval i=1/10 {
erase "$results\05_firmperformance\survival_ie_own`i'_peyes.dta"
erase "$results\05_firmperformance\survival_ie_prnt`i'_peyes.dta"
erase "$results\05_firmperformance\survival_ie_own`i'_peno.dta"
erase "$results\05_firmperformance\survival_ie_prnt`i'_peno.dta"
}

********************************************************************************

/*
Second, survival means not going bankrupt
*/

use "$data\01_main\firmlifespan_bnkrpt.dta", clear

forval i=1/10 {
	preserve
	keep if prnt_entr==1
	keep if dile_dspi_own==`i'
	collapse bnkrpt, by(age)
	drop if age>10
	gen cumul_bnkrpt = bnkrpt[1]
	replace cumul_bnkrpt = bnkrpt[_n] + cumul_bnkrpt[_n-1] if _n>1
	gen survival=1-cumul_bnkrpt
	keep age survival
	rename survival survival_newie_own`i'_peyes
	save "$results\05_firmperformance\survival_ie_own`i'_peyes.dta", replace
	restore
}
forval i=1/10 {
	preserve
	keep if prnt_entr==1
	keep if dile_dspi_prnt==`i'
	collapse bnkrpt, by(age)
	drop if age>10
	gen cumul_bnkrpt = bnkrpt[1]
	replace cumul_bnkrpt = bnkrpt[_n] + cumul_bnkrpt[_n-1] if _n>1
	gen survival=1-cumul_bnkrpt
	keep age survival
	rename survival survival_newie_prnt`i'_peyes
	save "$results\05_firmperformance\survival_ie_prnt`i'_peyes.dta", replace
	restore
}
forval i=1/10 {
	preserve
	keep if prnt_entr==0
	keep if dile_dspi_own==`i'
	collapse bnkrpt, by(age)
	drop if age>10
	gen cumul_bnkrpt = bnkrpt[1]
	replace cumul_bnkrpt = bnkrpt[_n] + cumul_bnkrpt[_n-1] if _n>1
	gen survival=1-cumul_bnkrpt
	keep age survival
	rename survival survival_newie_own`i'_peno
	save "$results\05_firmperformance\survival_ie_own`i'_peno.dta", replace
	restore
}
forval i=1/10 {
	preserve
	keep if prnt_entr==0
	keep if dile_dspi_prnt==`i'
	collapse bnkrpt, by(age)
	drop if age>10
	gen cumul_bnkrpt = bnkrpt[1]
	replace cumul_bnkrpt = bnkrpt[_n] + cumul_bnkrpt[_n-1] if _n>1
	gen survival=1-cumul_bnkrpt
	keep age survival
	rename survival survival_newie_prnt`i'_peno
	save "$results\05_firmperformance\survival_ie_prnt`i'_peno.dta", replace
	restore
}

/*
Combine
*/

use "$results\05_firmperformance\survival_ie_own1_peyes", clear
forval i=2/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_own`i'_peyes"
drop _merge
}
forval i=1/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_prnt`i'_peyes"
drop _merge
}
forval i=1/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_own`i'_peno"
drop _merge
}
forval i=1/10 {
merge 1:1 age using "$results\05_firmperformance\survival_ie_prnt`i'_peno"
drop _merge
}
save "$results\05_firmperformance\survival_byranks_byprnte_notbrupt.dta", replace
forval i=1/10 {
erase "$results\05_firmperformance\survival_ie_own`i'_peyes.dta"
erase "$results\05_firmperformance\survival_ie_prnt`i'_peyes.dta"
erase "$results\05_firmperformance\survival_ie_own`i'_peno.dta"
erase "$results\05_firmperformance\survival_ie_prnt`i'_peno.dta"
}

********************************************************************************

/*
Combine the two
*/

use "$results\05_firmperformance\survival_byranks_byprnte_filedtaxes.dta", clear
gen spec="taxfile"
append using "$results\05_firmperformance\survival_byranks_byprnte_notbrupt.dta"
order spec
replace spec="bankrupt" if spec==""

label var spec "Survival either filing taxes or not being bankrupt"
label var age "Firm age in years"
forval i=1/10 {
label var survival_newie_own`i'_peyes "Survival among those with entrepreneurial parents and decile `i' at t-1"
label var survival_newie_prnt`i'_peyes "Survival among those with entrepreneurial parents and decile `i' parents"
label var survival_newie_own`i'_peno "Survival among those with non-entrepreneurial parents and decile `i' at t-1"
label var survival_newie_prnt`i'_peno "Survival among those with non-entrepreneurial parents and decile `i' parents"
}

save "$results\05_firmperformance\fig7_figA10_figA11.dta", replace
erase "$results\05_firmperformance\survival_byranks_byprnte_filedtaxes.dta"
erase "$results\05_firmperformance\survival_byranks_byprnte_notbrupt.dta"

/*
________________________________________________________________________________
Figure 8: Firm-level outcomes by individual income and parental entrepreneurship
*/

use "$data\01_main\folk_flown_merge_eventready_iespec.dta", clear
merge 1:1 shnro vuosi using "$data\01_main\folk_flown_merge_eventready.dta", keepusing(ptile_dspi prnt_entr event_ie) keep(3)
drop _merge

* Keep only individuals who we can follow for ten years
bysort shnro: gen nobs = _N
keep if nobs==11
drop nobs

* Define decile ranks
egen dile_own = cut(ptile_dspi), at(1(10)101)
    replace dile_own=2 if dile_own==11
    replace dile_own=3 if dile_own==21
    replace dile_own=4 if dile_own==31
    replace dile_own=5 if dile_own==41
    replace dile_own=6 if dile_own==51
    replace dile_own=7 if dile_own==61
    replace dile_own=8 if dile_own==71
    replace dile_own=9 if dile_own==81
    replace dile_own=10 if dile_own==91

* Adjust sales, staff costs, value added and productivity for inflation
foreach var of varlist sales stfc va prod {
	replace `var' = `var' / 0.8960 if vuosi==1998
	replace `var' = `var' / 0.9070 if vuosi==1999
	replace `var' = `var' / 0.9340 if vuosi==2000
	replace `var' = `var' / 0.9590 if vuosi==2001
	replace `var' = `var' / 0.9780 if vuosi==2002
	replace `var' = `var' / 0.9910 if vuosi==2003
	replace `var' = `var' / 0.9920 if vuosi==2004
	replace `var' = `var' if vuosi==2005
	replace `var' = `var' / 1.0130 if vuosi==2006
	replace `var' = `var' / 1.0290 if vuosi==2007
	replace `var' = `var' / 1.0690 if vuosi==2008
	replace `var' = `var' / 1.0870 if vuosi==2009
	replace `var' = `var' / 1.1050 if vuosi==2010
	replace `var' = `var' / 1.1420 if vuosi==2011
	replace `var' = `var' / 1.1780 if vuosi==2012
	replace `var' = `var' / 1.2037 if vuosi==2013
	replace `var' = `var' / 1.2183 if vuosi==2014
	replace `var' = `var' / 1.2164 if vuosi==2015
	replace `var' = `var' / 1.2211 if vuosi==2016
	replace `var' = `var' / 1.2313 if vuosi==2017
	replace `var' = `var' / 1.2457 if vuosi==2018
	replace `var' = `var' / 1.2599 if vuosi==2019
}

* Cumulative outcomes
foreach var of varlist sales - prod {
	bysort shnro: egen ttl_`var'=total(`var')
}
foreach var of varlist ttl_sales - ttl_prod {
	replace `var'=1 if `var'<=0
}
foreach var of varlist ttl_sales - ttl_prod {
	replace `var' = log(`var')
}

* Did they ever do R&D?
merge m:1 syrtun vuosi using "W:\Inequality\2022\Data\rd_and_patents\R_D.dta", keepusing(R_D_research_added) keep(1 3)
drop _merge
gen rd=1
replace rd=0 if R_D_research_added==0 | R_D_research_added==.
bysort shnro: egen rd_ever=max(rd)

* Keep one line for each entrepreneur (firm)
keep if event_ie==0
drop if firm_ind==. | eq==.

* Binned scatterplots
cd "$results\05_firmperformance"
foreach var of varlist ttl_sales ttl_empl ttl_stfc ttl_va ttl_prod rd_ever {
binsreg `var' dile_own i.firm_ind eq if prnt_entr==1, ci(T) cb(T) nbins(10) savedata(fig8_`var'_peyes) replace
binsreg `var' dile_own i.firm_ind eq if prnt_entr==0, ci(T) cb(T) nbins(10) savedata(fig8_`var'_peno) replace
}
gr drop _all

* Combine files
use dots_x dots_fit CI_l CI_r using fig8_ttl_sales_peyes, clear
rename dots_fit ttl_sales_peyes
rename CI_l ttl_sales_peyes_95lo
rename CI_r ttl_sales_peyes_95up
foreach x in ttl_empl_peyes ttl_stfc_peyes ttl_va_peyes ttl_prod_peyes rd_ever_peyes ttl_sales_peno ttl_empl_peno ttl_stfc_peno ttl_va_peno ttl_prod_peno rd_ever_peno {
	merge 1:1 dots_x using fig8_`x'
	drop _merge
	rename dots_fit `x'
	rename CI_l `x'_95lo
	rename CI_r `x'_95up
}
rename dots_x decile
keep decile ttl* rd*

foreach x in ttl_sales_peyes ttl_empl_peyes ttl_stfc_peyes ttl_va_peyes ttl_prod_peyes rd_ever_peyes ttl_sales_peno ttl_empl_peno ttl_stfc_peno ttl_va_peno ttl_prod_peno rd_ever_peno {
	erase fig8_`x'.dta
}

label var ttl_sales_peyes "Total sales over first 10 years among those with entrepreneurial parents"
label var ttl_empl_peyes "Total number of employees over first 10 years among those with entrepreneurial parents"
label var ttl_stfc_peyes "Total staff costs over first 10 years among those with entrepreneurial parents"
label var ttl_va_peyes "Total value added over first 10 years among those with entrepreneurial parents"
label var ttl_prod_peyes "Total productivity over first 10 years among those with entrepreneurial parents"
label var rd_ever_peyes "Share with any R&D over first 10 years among those with entrepreneurial parents"
label var ttl_sales_peno "Total sales over first 10 years among those with non-entrep. parents"
label var ttl_empl_peno "Total number of employees over first 10 years among those with non-entrep. parents"
label var ttl_stfc_peno "Total staff costs over first 10 years among those with non-entrep. parents"
label var ttl_va_peno "Total value added over first 10 years among those with non-entrep. parents"
label var ttl_prod_peno "Total productivity over first 10 years among those with non-entrep. parents"
label var rd_ever_peno "Share with any R&D over first 10 years among those with non-entrep. parents"

save "$results\05_firmperformance\fig8.dta", replace

/*
________________________________________________________________________________
Figure 9: Firm-level outcomes by parental income and parental entrepreneurship
*/

use "$data\01_main\folk_flown_merge_eventready_iespec.dta", clear
merge 1:1 shnro vuosi using "$data\01_main\folk_flown_merge_eventready.dta", keepusing(ptile_prnt prnt_entr event_ie) keep(3)
drop _merge

* Keep only individuals who we can follow for ten years
bysort shnro: gen nobs = _N
keep if nobs==11
drop nobs

* Define decile ranks
egen dile_prnt = cut(ptile_prnt), at(1(10)101)
    replace dile_prnt=2 if dile_prnt==11
    replace dile_prnt=3 if dile_prnt==21
    replace dile_prnt=4 if dile_prnt==31
    replace dile_prnt=5 if dile_prnt==41
    replace dile_prnt=6 if dile_prnt==51
    replace dile_prnt=7 if dile_prnt==61
    replace dile_prnt=8 if dile_prnt==71
    replace dile_prnt=9 if dile_prnt==81
    replace dile_prnt=10 if dile_prnt==91

* Adjust sales, staff costs, value added and productivity for inflation
foreach var of varlist sales stfc va prod {
	replace `var' = `var' / 0.8960 if vuosi==1998
	replace `var' = `var' / 0.9070 if vuosi==1999
	replace `var' = `var' / 0.9340 if vuosi==2000
	replace `var' = `var' / 0.9590 if vuosi==2001
	replace `var' = `var' / 0.9780 if vuosi==2002
	replace `var' = `var' / 0.9910 if vuosi==2003
	replace `var' = `var' / 0.9920 if vuosi==2004
	replace `var' = `var' if vuosi==2005
	replace `var' = `var' / 1.0130 if vuosi==2006
	replace `var' = `var' / 1.0290 if vuosi==2007
	replace `var' = `var' / 1.0690 if vuosi==2008
	replace `var' = `var' / 1.0870 if vuosi==2009
	replace `var' = `var' / 1.1050 if vuosi==2010
	replace `var' = `var' / 1.1420 if vuosi==2011
	replace `var' = `var' / 1.1780 if vuosi==2012
	replace `var' = `var' / 1.2037 if vuosi==2013
	replace `var' = `var' / 1.2183 if vuosi==2014
	replace `var' = `var' / 1.2164 if vuosi==2015
	replace `var' = `var' / 1.2211 if vuosi==2016
	replace `var' = `var' / 1.2313 if vuosi==2017
	replace `var' = `var' / 1.2457 if vuosi==2018
	replace `var' = `var' / 1.2599 if vuosi==2019
}

* Cumulative outcomes
foreach var of varlist sales - prod {
	bysort shnro: egen ttl_`var'=total(`var')
}
foreach var of varlist ttl_sales - ttl_prod {
	replace `var'=1 if `var'<=0
}
foreach var of varlist ttl_sales - ttl_prod {
	replace `var' = log(`var')
}

* Did they ever do R&D?
merge m:1 syrtun vuosi using "W:\Inequality\2022\Data\rd_and_patents\R_D.dta", keepusing(R_D_research_added) keep(1 3)
drop _merge
gen rd=1
replace rd=0 if R_D_research_added==0 | R_D_research_added==.
bysort shnro: egen rd_ever=max(rd)

* Keep one line for each entrepreneur (firm)
keep if event_ie==0
drop if firm_ind==. | eq==.

* Binned scatterplots
cd "$results\05_firmperformance"
foreach var of varlist ttl_sales ttl_empl ttl_stfc ttl_va ttl_prod rd_ever {
binsreg `var' dile_prnt i.firm_ind eq if prnt_entr==1, ci(T) cb(T) nbins(10) savedata(fig8_`var'_peyes) replace
binsreg `var' dile_prnt i.firm_ind eq if prnt_entr==0, ci(T) cb(T) nbins(10) savedata(fig8_`var'_peno) replace
}
gr drop _all

* Combine files
use dots_x dots_fit CI_l CI_r using fig8_ttl_sales_peyes, clear
rename dots_fit ttl_sales_peyes
rename CI_l ttl_sales_peyes_95lo
rename CI_r ttl_sales_peyes_95up
foreach x in ttl_empl_peyes ttl_stfc_peyes ttl_va_peyes ttl_prod_peyes rd_ever_peyes ttl_sales_peno ttl_empl_peno ttl_stfc_peno ttl_va_peno ttl_prod_peno rd_ever_peno {
	merge 1:1 dots_x using fig8_`x'
	drop _merge
	rename dots_fit `x'
	rename CI_l `x'_95lo
	rename CI_r `x'_95up
}
rename dots_x decile
keep decile ttl* rd*

foreach x in ttl_sales_peyes ttl_empl_peyes ttl_stfc_peyes ttl_va_peyes ttl_prod_peyes rd_ever_peyes ttl_sales_peno ttl_empl_peno ttl_stfc_peno ttl_va_peno ttl_prod_peno rd_ever_peno {
	erase fig8_`x'.dta
}

label var ttl_sales_peyes "Total sales over first 10 years among those with entrepreneurial parents"
label var ttl_empl_peyes "Total number of employees over first 10 years among those with entrepreneurial parents"
label var ttl_stfc_peyes "Total staff costs over first 10 years among those with entrepreneurial parents"
label var ttl_va_peyes "Total value added over first 10 years among those with entrepreneurial parents"
label var ttl_prod_peyes "Total productivity over first 10 years among those with entrepreneurial parents"
label var rd_ever_peyes "Share with any R&D over first 10 years among those with entrepreneurial parents"
label var ttl_sales_peno "Total sales over first 10 years among those with non-entrep. parents"
label var ttl_empl_peno "Total number of employees over first 10 years among those with non-entrep. parents"
label var ttl_stfc_peno "Total staff costs over first 10 years among those with non-entrep. parents"
label var ttl_va_peno "Total value added over first 10 years among those with non-entrep. parents"
label var ttl_prod_peno "Total productivity over first 10 years among those with non-entrep. parents"
label var rd_ever_peno "Share with any R&D over first 10 years among those with non-entrep. parents"

save "$results\05_firmperformance\fig9.dta", replace









/*
________________________________________________________________________________
Appendix
*/

/*
________________________________________________________________________________
Table A3: Firm-level outcomes: Comparing the relative importance of various predictors using dominance analysis
*/

********************************************************************************

* The firm data on employment and value added

use "$data\01_main\folk_flown_merge_eventready_iespec.dta", clear

* Keep only individuals who we can follow for ten years
bysort shnro: gen nobs = _N
keep if nobs==11
drop nobs

* Adjust value added for inflation
	replace va = va / 0.8960 if vuosi==1998
	replace va = va / 0.9070 if vuosi==1999
	replace va = va / 0.9340 if vuosi==2000
	replace va = va / 0.9590 if vuosi==2001
	replace va = va / 0.9780 if vuosi==2002
	replace va = va / 0.9910 if vuosi==2003
	replace va = va / 0.9920 if vuosi==2004
	replace va = va if vuosi==2005
	replace va = va / 1.0130 if vuosi==2006
	replace va = va / 1.0290 if vuosi==2007
	replace va = va / 1.0690 if vuosi==2008
	replace va = va / 1.0870 if vuosi==2009
	replace va = va / 1.1050 if vuosi==2010
	replace va = va / 1.1420 if vuosi==2011
	replace va = va / 1.1780 if vuosi==2012
	replace va = va / 1.2037 if vuosi==2013
	replace va = va / 1.2183 if vuosi==2014
	replace va = va / 1.2164 if vuosi==2015
	replace va = va / 1.2211 if vuosi==2016
	replace va = va / 1.2313 if vuosi==2017
	replace va = va / 1.2457 if vuosi==2018
	replace va = va / 1.2599 if vuosi==2019

* Cumulative outcomes
foreach var of varlist empl va {
	bysort shnro: egen ttl_`var'=total(`var')
}
foreach var of varlist ttl_empl ttl_va {
	replace `var'=1 if `var'<=0
}
foreach var of varlist ttl_empl ttl_va {
	replace `var' = log(`var')
}

keep shnro vuosi ttl_empl ttl_va firm_ind eq
drop if firm_ind==. | eq==.

* Only one row per entrepreneur (firm)
merge 1:1 shnro vuosi using "$data\01_main\folk_flown_merge_eventready.dta", keepusing(event_ie) keep(3)
keep if event_ie==0
drop vuosi event_ie _merge

save "$data\99_temp\temp_empl_va.dta", replace

********************************************************************************

* Entrepreneurs' characteristics etc.

use "$data\01_main\folk_flown_merge_eventready.dta", clear

* Restriction to have a common sample across the analysis: have to observe from t-1 to t+10
keep if event_ie==-1

* Dummy for unemployment at t-1
gen unempl=0
replace unempl=1 if (tyotur_dummy==1) & (event_ie==-1 | event_uie==-1 | event_we==-1)

* Dummy for studying at t-1
gen student=0
replace student=1 if (opira_dummy==1) & (event_ie==-1 | event_uie==-1 | event_we==-1)

******************************************

/*
Education more granularly
*/

* First, save our t-1 tags to be used when getting addtional data
preserve
keep if event_ie==-1
keep shnro vuosi
save "$data\99_temp\tm1tags.dta", replace
restore

* Second, education level and field
preserve
use vuosi shnro ututku_aste ututku_ala if vuosi>=1997 using "D:\ready-made\FOLK_perus_8800a\folk_19872000_tua_perus20tot_2.dta", clear
append using "D:\ready-made\FOLK_perus_0110a\folk_20012010_tua_perus20tot_2.dta", keep(vuosi shnro ututku_aste ututku_ala)
append using "D:\ready-made\FOLK_perus_11a\folk_20112019_tua_perus20tot_2.dta", keep(vuosi shnro ututku_aste ututku_ala)
merge 1:1 shnro vuosi using "$data\99_temp\tm1tags.dta", keep(3)
destring ututku_aste, replace
destring ututku_ala, replace
keep if inrange(vuosi,1997,2013)
drop _merge
save "$data\99_temp\ututku.dta", replace
restore
merge 1:1 shnro vuosi using "$data\99_temp\ututku.dta"
drop _merge

* We now have it for t-1. Extend for all years
rename ututku_aste ututku_aste_m1
rename ututku_ala ututku_ala_m1
bysort shnro: egen ututku_aste = max(ututku_aste_m1)
bysort shnro: egen ututku_ala = max(ututku_ala_m1)
replace ututku_aste=0 if ututku_aste==.
replace ututku_ala=0 if ututku_ala==.
drop *_m1

erase "$data\99_temp\tm1tags.dta"
erase "$data\99_temp\ututku.dta"

* Merge firm-level data
merge 1:1 shnro using "$data\99_temp\temp_empl_va.dta", keep(3)
erase "$data\99_temp\temp_empl_va.dta"

************************************

/*
Dominance analysis: number of employees
*/

* Directory
cd "$results\05_firmperformance"

preserve
* Define interactions ('domin' does not support i.var1#i.var2)
rename ika age
rename ikasq age2
rename sukup sex
gen age_x_sex=age*sex
gen age2_x_sex=age2*sex
gen age_x_ututku_aste=age*ututku_aste
gen age2_x_ututku_aste=age2*ututku_aste
gen age_x_ptile_dspi=age*ptile_dspi
gen age2_x_ptile_dspi=age2*ptile_dspi
gen age_x_ptile_prnt=age*ptile_prnt
gen age2_x_ptile_prnt=age2*ptile_prnt
gen age_x_prnt_entr=age*prnt_entr
gen age2_x_prnt_entr=age2*prnt_entr
gen sex_x_ututku_aste=sex*ututku_aste
gen sex_x_ptile_dspi=sex*ptile_dspi
gen sex_x_ptile_prnt=sex*ptile_prnt
gen sex_x_prnt_entr=sex*prnt_entr
gen ututku_aste_x_ptile_dspi=ututku_aste*ptile_dspi
gen ututku_aste_x_ptile_prnt=ututku_aste*ptile_prnt
gen ututku_aste_x_prnt_entr=ututku_aste*prnt_entr
gen ptile_dspi_x_ptile_prnt=ptile_dspi*ptile_prnt
gen ptile_dspi_x_prnt_entr=ptile_dspi*prnt_entr
gen ptile_prnt_x_prnt_entr=ptile_prnt*prnt_entr
gen eq_x_ind=firm_ind*eq
* The analysis
domin ttl_empl prnt_entr uie sex pks married unempl student, /// simple dummies
sets((i.ptile_dspi) (i.ptile_prnt) (i.tol2dig) (i.ututku_aste) (i.ututku_ala) (age age2) /// simple sets
(age_x_ptile_dspi age2_x_ptile_dspi sex_x_ptile_dspi ututku_aste_x_ptile_dspi /// own rank interactions
age_x_ptile_prnt age2_x_ptile_prnt sex_x_ptile_prnt ututku_aste_x_ptile_prnt /// parent rank interactions
age_x_prnt_entr age2_x_prnt_entr sex_x_prnt_entr ututku_aste_x_prnt_entr /// parent entrep. interactions
ptile_dspi_x_ptile_prnt ptile_dspi_x_prnt_entr ptile_prnt_x_prnt_entr) /// rank & parent entrep. interactions
(age_x_sex age2_x_sex age_x_ututku_aste age2_x_ututku_aste sex_x_ututku_aste) /// Mincerian interactions
(i.firm_ind eq eq_x_ind)) // industry, initial equity and their interactions
restore

* Save dominance statistics
preserve
matrix b=e(b)
gen nr=_n
gen domstat=.
forval i=1(1)16{
	replace domstat=b[1,`i'] if nr==`i'
}
replace domstat=e(N) if nr==17
replace domstat=e(fitstat_o) if nr==18
keep if nr<=18
keep nr domstat
rename domstat domstat_nrempl
save nrempl_domstat, replace
restore

* Save standardized dominance statistics
preserve
matrix b=e(std)
gen nr=_n
gen stddomstat=.
forval i=1(1)16{
	replace stddomstat=b[1,`i'] if nr==`i'
}
keep if nr<=16
keep nr stddomstat
rename stddomstat stddomstat_nrempl
save nrempl_stddomstat, replace
restore

* Save ranking
preserve
matrix b=e(ranking)
gen nr=_n
gen ranking=.
forval i=1(1)16{
	replace ranking=b[1,`i'] if nr==`i'
}
keep if nr<=16
keep nr ranking
rename ranking ranking_nrempl
save nrempl_ranking, replace
restore

************************************

/*
Dominance analysis: value added
*/

* Directory
cd "$results\05_firmperformance"

preserve
* Define interactions ('domin' does not support i.var1#i.var2)
rename ika age
rename ikasq age2
rename sukup sex
gen age_x_sex=age*sex
gen age2_x_sex=age2*sex
gen age_x_ututku_aste=age*ututku_aste
gen age2_x_ututku_aste=age2*ututku_aste
gen age_x_ptile_dspi=age*ptile_dspi
gen age2_x_ptile_dspi=age2*ptile_dspi
gen age_x_ptile_prnt=age*ptile_prnt
gen age2_x_ptile_prnt=age2*ptile_prnt
gen age_x_prnt_entr=age*prnt_entr
gen age2_x_prnt_entr=age2*prnt_entr
gen sex_x_ututku_aste=sex*ututku_aste
gen sex_x_ptile_dspi=sex*ptile_dspi
gen sex_x_ptile_prnt=sex*ptile_prnt
gen sex_x_prnt_entr=sex*prnt_entr
gen ututku_aste_x_ptile_dspi=ututku_aste*ptile_dspi
gen ututku_aste_x_ptile_prnt=ututku_aste*ptile_prnt
gen ututku_aste_x_prnt_entr=ututku_aste*prnt_entr
gen ptile_dspi_x_ptile_prnt=ptile_dspi*ptile_prnt
gen ptile_dspi_x_prnt_entr=ptile_dspi*prnt_entr
gen ptile_prnt_x_prnt_entr=ptile_prnt*prnt_entr
gen eq_x_ind=firm_ind*eq
* The analysis
domin ttl_va prnt_entr uie sex pks married unempl student, /// simple dummies
sets((i.ptile_dspi) (i.ptile_prnt) (i.tol2dig) (i.ututku_aste) (i.ututku_ala) (age age2) /// simple sets
(age_x_ptile_dspi age2_x_ptile_dspi sex_x_ptile_dspi ututku_aste_x_ptile_dspi /// own rank interactions
age_x_ptile_prnt age2_x_ptile_prnt sex_x_ptile_prnt ututku_aste_x_ptile_prnt /// parent rank interactions
age_x_prnt_entr age2_x_prnt_entr sex_x_prnt_entr ututku_aste_x_prnt_entr /// parent entrep. interactions
ptile_dspi_x_ptile_prnt ptile_dspi_x_prnt_entr ptile_prnt_x_prnt_entr) /// rank & parent entrep. interactions
(age_x_sex age2_x_sex age_x_ututku_aste age2_x_ututku_aste sex_x_ututku_aste) /// Mincerian interactions
(i.firm_ind eq eq_x_ind)) // industry, initial equity and their interactions
restore

* Save dominance statistics
preserve
matrix b=e(b)
gen nr=_n
gen domstat=.
forval i=1(1)16{
	replace domstat=b[1,`i'] if nr==`i'
}
replace domstat=e(N) if nr==17
replace domstat=e(fitstat_o) if nr==18
keep if nr<=18
keep nr domstat
rename domstat domstat_va
save va_domstat, replace
restore

* Save standardized dominance statistics
preserve
matrix b=e(std)
gen nr=_n
gen stddomstat=.
forval i=1(1)16{
	replace stddomstat=b[1,`i'] if nr==`i'
}
keep if nr<=16
keep nr stddomstat
rename stddomstat stddomstat_va
save va_stddomstat, replace
restore

* Save ranking
preserve
matrix b=e(ranking)
gen nr=_n
gen ranking=.
forval i=1(1)16{
	replace ranking=b[1,`i'] if nr==`i'
}
keep if nr<=16
keep nr ranking
rename ranking ranking_va
save va_ranking, replace
restore

************************************

/*
Merge the above results into single file
*/

use nrempl_domstat, clear
merge 1:1 nr using nrempl_stddomstat
drop _merge
merge 1:1 nr using nrempl_ranking
drop _merge
merge 1:1 nr using va_domstat
drop _merge
merge 1:1 nr using va_stddomstat
drop _merge
merge 1:1 nr using va_ranking
drop _merge

gen predictor=""
replace predictor="Parent entrepreneur" if nr==1
replace predictor="Unincorporated at t-1" if nr==2
replace predictor="Gender" if nr==3
replace predictor="Capital region at t-1" if nr==4
replace predictor="Married at t-1" if nr==5
replace predictor="Unemployed at t-1" if nr==6
replace predictor="Student at t-1" if nr==7
replace predictor="Individual rank at t-1" if nr==8
replace predictor="Parental rank" if nr==9
replace predictor="Industry at t-1" if nr==10
replace predictor="Level of highest degree at t-1" if nr==11
replace predictor="Field of highest degree at t-1" if nr==12
replace predictor="Age (linear and quadratic)" if nr==13
replace predictor="Mincerian interactions" if nr==14
replace predictor="Other interactions" if nr==15
replace predictor="Firm-specific" if nr==16
replace predictor="Number of observations" if nr==17
replace predictor="Total R2 of the full model" if nr==18
order predictor

save tabA3, replace
erase nrempl_domstat.dta
erase nrempl_stddomstat.dta
erase nrempl_ranking.dta
erase va_domstat.dta
erase va_stddomstat.dta
erase va_ranking.dta

/*
________________________________________________________________________________
Figure A12: Firm-level outcomes by individual income and parental entrepreneurship within the top decile of individual income
*/

use "$data\01_main\folk_flown_merge_eventready_iespec.dta", clear
merge 1:1 shnro vuosi using "$data\01_main\folk_flown_merge_eventready.dta", keepusing(ptile_dspi prnt_entr event_ie) keep(3)
drop _merge
keep if inrange(ptile_dspi,91,100)

* Keep only individuals who we can follow for ten years
bysort shnro: gen nobs = _N
keep if nobs==11
drop nobs

* Adjust sales, staff costs, value added and productivity for inflation
foreach var of varlist sales stfc va prod {
	replace `var' = `var' / 0.8960 if vuosi==1998
	replace `var' = `var' / 0.9070 if vuosi==1999
	replace `var' = `var' / 0.9340 if vuosi==2000
	replace `var' = `var' / 0.9590 if vuosi==2001
	replace `var' = `var' / 0.9780 if vuosi==2002
	replace `var' = `var' / 0.9910 if vuosi==2003
	replace `var' = `var' / 0.9920 if vuosi==2004
	replace `var' = `var' if vuosi==2005
	replace `var' = `var' / 1.0130 if vuosi==2006
	replace `var' = `var' / 1.0290 if vuosi==2007
	replace `var' = `var' / 1.0690 if vuosi==2008
	replace `var' = `var' / 1.0870 if vuosi==2009
	replace `var' = `var' / 1.1050 if vuosi==2010
	replace `var' = `var' / 1.1420 if vuosi==2011
	replace `var' = `var' / 1.1780 if vuosi==2012
	replace `var' = `var' / 1.2037 if vuosi==2013
	replace `var' = `var' / 1.2183 if vuosi==2014
	replace `var' = `var' / 1.2164 if vuosi==2015
	replace `var' = `var' / 1.2211 if vuosi==2016
	replace `var' = `var' / 1.2313 if vuosi==2017
	replace `var' = `var' / 1.2457 if vuosi==2018
	replace `var' = `var' / 1.2599 if vuosi==2019
}

* Cumulative outcomes
foreach var of varlist sales - prod {
	bysort shnro: egen ttl_`var'=total(`var')
}
foreach var of varlist ttl_sales - ttl_prod {
	replace `var'=1 if `var'<=0
}
foreach var of varlist ttl_sales - ttl_prod {
	replace `var' = log(`var')
}

* Did they ever do R&D?
merge m:1 syrtun vuosi using "W:\Inequality\2022\Data\rd_and_patents\R_D.dta", keepusing(R_D_research_added) keep(1 3)
drop _merge
gen rd=1
replace rd=0 if R_D_research_added==0 | R_D_research_added==.
bysort shnro: egen rd_ever=max(rd)

* Keep one line for each entrepreneur (firm)
keep if event_ie==0
drop if firm_ind==. | eq==.

* Binned scatterplots
cd "$results\05_firmperformance"
foreach var of varlist ttl_sales ttl_empl ttl_stfc ttl_va ttl_prod rd_ever {
binsreg `var' ptile_dspi i.firm_ind eq if prnt_entr==1, ci(T) cb(T) nbins(10) savedata(figA12_`var'_peyes) replace
binsreg `var' ptile_dspi i.firm_ind eq if prnt_entr==0, ci(T) cb(T) nbins(10) savedata(figA12_`var'_peno) replace
}
gr drop _all

* Combine files
use dots_x dots_fit CI_l CI_r using figA12_ttl_sales_peyes, clear
rename dots_fit ttl_sales_peyes
rename CI_l ttl_sales_peyes_95lo
rename CI_r ttl_sales_peyes_95up
foreach x in ttl_empl_peyes ttl_stfc_peyes ttl_va_peyes ttl_prod_peyes rd_ever_peyes ttl_sales_peno ttl_empl_peno ttl_stfc_peno ttl_va_peno ttl_prod_peno rd_ever_peno {
	merge 1:1 dots_x using figA12_`x'
	drop _merge
	rename dots_fit `x'
	rename CI_l `x'_95lo
	rename CI_r `x'_95up
}
rename dots_x ptile
keep ptile ttl* rd*

foreach x in ttl_sales_peyes ttl_empl_peyes ttl_stfc_peyes ttl_va_peyes ttl_prod_peyes rd_ever_peyes ttl_sales_peno ttl_empl_peno ttl_stfc_peno ttl_va_peno ttl_prod_peno rd_ever_peno {
	erase figA12_`x'.dta
}

label var ttl_sales_peyes "Total sales over first 10 years among those with entrepreneurial parents"
label var ttl_empl_peyes "Total number of employees over first 10 years among those with entrepreneurial parents"
label var ttl_stfc_peyes "Total staff costs over first 10 years among those with entrepreneurial parents"
label var ttl_va_peyes "Total value added over first 10 years among those with entrepreneurial parents"
label var ttl_prod_peyes "Total productivity over first 10 years among those with entrepreneurial parents"
label var rd_ever_peyes "Share with any R&D over first 10 years among those with entrepreneurial parents"
label var ttl_sales_peno "Total sales over first 10 years among those with non-entrep. parents"
label var ttl_empl_peno "Total number of employees over first 10 years among those with non-entrep. parents"
label var ttl_stfc_peno "Total staff costs over first 10 years among those with non-entrep. parents"
label var ttl_va_peno "Total value added over first 10 years among those with non-entrep. parents"
label var ttl_prod_peno "Total productivity over first 10 years among those with non-entrep. parents"
label var rd_ever_peno "Share with any R&D over first 10 years among those with non-entrep. parents"

save "$results\05_firmperformance\figA12.dta", replace

/*
________________________________________________________________________________
Figure A13: Firm-level outcomes by individual income and parental entrepreneurship: conditional on survival until t+10
*/

use "$data\01_main\folk_flown_merge_eventready_iespec.dta", clear
merge 1:1 shnro vuosi using "$data\01_main\folk_flown_merge_eventready.dta", keepusing(ptile_dspi prnt_entr event_ie) keep(3)
drop _merge

* Keep only individuals who we can follow for ten years
bysort shnro: gen nobs = _N
keep if nobs==11
drop nobs

* Define decile ranks
egen dile_own = cut(ptile_dspi), at(1(10)101)
    replace dile_own=2 if dile_own==11
    replace dile_own=3 if dile_own==21
    replace dile_own=4 if dile_own==31
    replace dile_own=5 if dile_own==41
    replace dile_own=6 if dile_own==51
    replace dile_own=7 if dile_own==61
    replace dile_own=8 if dile_own==71
    replace dile_own=9 if dile_own==81
    replace dile_own=10 if dile_own==91

* Adjust sales, staff costs, value added and productivity for inflation
foreach var of varlist sales stfc va prod {
	replace `var' = `var' / 0.8960 if vuosi==1998
	replace `var' = `var' / 0.9070 if vuosi==1999
	replace `var' = `var' / 0.9340 if vuosi==2000
	replace `var' = `var' / 0.9590 if vuosi==2001
	replace `var' = `var' / 0.9780 if vuosi==2002
	replace `var' = `var' / 0.9910 if vuosi==2003
	replace `var' = `var' / 0.9920 if vuosi==2004
	replace `var' = `var' if vuosi==2005
	replace `var' = `var' / 1.0130 if vuosi==2006
	replace `var' = `var' / 1.0290 if vuosi==2007
	replace `var' = `var' / 1.0690 if vuosi==2008
	replace `var' = `var' / 1.0870 if vuosi==2009
	replace `var' = `var' / 1.1050 if vuosi==2010
	replace `var' = `var' / 1.1420 if vuosi==2011
	replace `var' = `var' / 1.1780 if vuosi==2012
	replace `var' = `var' / 1.2037 if vuosi==2013
	replace `var' = `var' / 1.2183 if vuosi==2014
	replace `var' = `var' / 1.2164 if vuosi==2015
	replace `var' = `var' / 1.2211 if vuosi==2016
	replace `var' = `var' / 1.2313 if vuosi==2017
	replace `var' = `var' / 1.2457 if vuosi==2018
	replace `var' = `var' / 1.2599 if vuosi==2019
}

foreach var of varlist sales - prod {
	replace `var'=1 if `var'<=0
}
foreach var of varlist sales - prod {
	replace `var' = log(`var')
}

* R&D data
merge m:1 syrtun vuosi using "W:\Inequality\2022\Data\rd_and_patents\R_D.dta", keepusing(R_D_research_added) keep(1 3)
drop _merge
gen rd=1
replace rd=0 if R_D_research_added==0 | R_D_research_added==.

* Save initial equity
preserve
keep if event_ie==0
keep shnro eq
save "$data\99_temp\temp_eq.dta", replace
restore

* Keep one line for each entrepreneur (firm)
keep if event_ie==10
drop if sales==.
merge 1:1 shnro using "$data\99_temp\temp_eq.dta", keep(3)
drop if firm_ind==. | eq==.
erase "$data\99_temp\temp_eq.dta"

* Binned scatterplots
cd "$results\05_firmperformance"
foreach var of varlist sales empl stfc va prod rd {
binsreg `var' dile_own i.firm_ind eq if prnt_entr==1, ci(T) cb(T) nbins(10) savedata(figA13_`var'_peyes) replace
binsreg `var' dile_own i.firm_ind eq if prnt_entr==0, ci(T) cb(T) nbins(10) savedata(figA13_`var'_peno) replace
}
gr drop _all

* Combine files
use dots_x dots_fit CI_l CI_r using figA13_sales_peyes, clear
rename dots_fit sales_peyes
rename CI_l sales_peyes_95lo
rename CI_r sales_peyes_95up
foreach x in empl_peyes stfc_peyes va_peyes prod_peyes rd_peyes sales_peno empl_peno stfc_peno va_peno prod_peno rd_peno {
	merge 1:1 dots_x using figA13_`x'
	drop _merge
	rename dots_fit `x'
	rename CI_l `x'_95lo
	rename CI_r `x'_95up
}
rename dots_x decile
keep decile sales* empl* stfc* va* prod* rd*

foreach x in sales_peyes empl_peyes stfc_peyes va_peyes prod_peyes rd_peyes sales_peno empl_peno stfc_peno va_peno prod_peno rd_peno {
	erase figA13_`x'.dta
}

label var sales_peyes "Sales at t+10 among those with entrepreneurial parents"
label var empl_peyes "Number of employees at t+10 among those with entrepreneurial parents"
label var stfc_peyes "Staff costs at t+10 among those with entrepreneurial parents"
label var va_peyes "Value added at t+10 among those with entrepreneurial parents"
label var prod_peyes "Productivity at t+10 among those with entrepreneurial parents"
label var rd_peyes "Share with any R&D at t+10 among those with entrepreneurial parents"
label var sales_peno "Sales at t+10 among those with non-entrep. parents"
label var empl_peno "Number of employees at t+10 among those with non-entrep. parents"
label var stfc_peno "Staff costs at t+10 among those with non-entrep. parents"
label var va_peno "Value added at t+10 among those with non-entrep. parents"
label var prod_peno "Productivity at t+10 among those with non-entrep. parents"
label var rd_peno "Share with any R&D at t+10 among those with non-entrep. parents"

save "$results\05_firmperformance\figA13.dta", replace

/*
________________________________________________________________________________
Figure A14: Firm-level outcomes by parental income and parental entrepreneurship: conditional on survival until t+10
*/

use "$data\01_main\folk_flown_merge_eventready_iespec.dta", clear
merge 1:1 shnro vuosi using "$data\01_main\folk_flown_merge_eventready.dta", keepusing(ptile_prnt prnt_entr event_ie) keep(3)
drop _merge

* Keep only individuals who we can follow for ten years
bysort shnro: gen nobs = _N
keep if nobs==11
drop nobs

* Define decile ranks
egen dile_prnt = cut(ptile_prnt), at(1(10)101)
    replace dile_prnt=2 if dile_prnt==11
    replace dile_prnt=3 if dile_prnt==21
    replace dile_prnt=4 if dile_prnt==31
    replace dile_prnt=5 if dile_prnt==41
    replace dile_prnt=6 if dile_prnt==51
    replace dile_prnt=7 if dile_prnt==61
    replace dile_prnt=8 if dile_prnt==71
    replace dile_prnt=9 if dile_prnt==81
    replace dile_prnt=10 if dile_prnt==91

* Adjust sales, staff costs, value added and productivity for inflation
foreach var of varlist sales stfc va prod {
	replace `var' = `var' / 0.8960 if vuosi==1998
	replace `var' = `var' / 0.9070 if vuosi==1999
	replace `var' = `var' / 0.9340 if vuosi==2000
	replace `var' = `var' / 0.9590 if vuosi==2001
	replace `var' = `var' / 0.9780 if vuosi==2002
	replace `var' = `var' / 0.9910 if vuosi==2003
	replace `var' = `var' / 0.9920 if vuosi==2004
	replace `var' = `var' if vuosi==2005
	replace `var' = `var' / 1.0130 if vuosi==2006
	replace `var' = `var' / 1.0290 if vuosi==2007
	replace `var' = `var' / 1.0690 if vuosi==2008
	replace `var' = `var' / 1.0870 if vuosi==2009
	replace `var' = `var' / 1.1050 if vuosi==2010
	replace `var' = `var' / 1.1420 if vuosi==2011
	replace `var' = `var' / 1.1780 if vuosi==2012
	replace `var' = `var' / 1.2037 if vuosi==2013
	replace `var' = `var' / 1.2183 if vuosi==2014
	replace `var' = `var' / 1.2164 if vuosi==2015
	replace `var' = `var' / 1.2211 if vuosi==2016
	replace `var' = `var' / 1.2313 if vuosi==2017
	replace `var' = `var' / 1.2457 if vuosi==2018
	replace `var' = `var' / 1.2599 if vuosi==2019
}

foreach var of varlist sales - prod {
	replace `var'=1 if `var'<=0
}
foreach var of varlist sales - prod {
	replace `var' = log(`var')
}

* R&D data
merge m:1 syrtun vuosi using "W:\Inequality\2022\Data\rd_and_patents\R_D.dta", keepusing(R_D_research_added) keep(1 3)
drop _merge
gen rd=1
replace rd=0 if R_D_research_added==0 | R_D_research_added==.

* Save initial equity
preserve
keep if event_ie==0
keep shnro eq
save "$data\99_temp\temp_eq.dta", replace
restore

* Keep one line for each entrepreneur (firm)
keep if event_ie==10
drop if sales==.
merge 1:1 shnro using "$data\99_temp\temp_eq.dta", keep(3)
drop if firm_ind==. | eq==.
erase "$data\99_temp\temp_eq.dta"

* Binned scatterplots
cd "$results\05_firmperformance"
foreach var of varlist sales empl stfc va prod rd {
binsreg `var' dile_prnt i.firm_ind eq if prnt_entr==1, ci(T) cb(T) nbins(10) savedata(figA14_`var'_peyes) replace
binsreg `var' dile_prnt i.firm_ind eq if prnt_entr==0, ci(T) cb(T) nbins(10) savedata(figA14_`var'_peno) replace
}
gr drop _all

* Combine files
use dots_x dots_fit CI_l CI_r using figA14_sales_peyes, clear
rename dots_fit sales_peyes
rename CI_l sales_peyes_95lo
rename CI_r sales_peyes_95up
foreach x in empl_peyes stfc_peyes va_peyes prod_peyes rd_peyes sales_peno empl_peno stfc_peno va_peno prod_peno rd_peno {
	merge 1:1 dots_x using figA14_`x'
	drop _merge
	rename dots_fit `x'
	rename CI_l `x'_95lo
	rename CI_r `x'_95up
}
rename dots_x decile
keep decile sales* empl* stfc* va* prod* rd*

foreach x in sales_peyes empl_peyes stfc_peyes va_peyes prod_peyes rd_peyes sales_peno empl_peno stfc_peno va_peno prod_peno rd_peno {
	erase figA14_`x'.dta
}

label var sales_peyes "Sales at t+10 among those with entrepreneurial parents"
label var empl_peyes "Number of employees at t+10 among those with entrepreneurial parents"
label var stfc_peyes "Staff costs at t+10 among those with entrepreneurial parents"
label var va_peyes "Value added at t+10 among those with entrepreneurial parents"
label var prod_peyes "Productivity at t+10 among those with entrepreneurial parents"
label var rd_peyes "Share with any R&D at t+10 among those with entrepreneurial parents"
label var sales_peno "Sales at t+10 among those with non-entrep. parents"
label var empl_peno "Number of employees at t+10 among those with non-entrep. parents"
label var stfc_peno "Staff costs at t+10 among those with non-entrep. parents"
label var va_peno "Value added at t+10 among those with non-entrep. parents"
label var prod_peno "Productivity at t+10 among those with non-entrep. parents"
label var rd_peno "Share with any R&D at t+10 among those with non-entrep. parents"

save "$results\05_firmperformance\figA14.dta", replace
